<?php

class LiveController extends Zend_Controller_Action
{

    public function init()
    {
        /* Initialize action controller here */
    }

    public function indexAction()
    {
                
                $db = Zend_Registry:: get('db');
                $select = $db->select()
                        ->from(array('r'=>'rooms'),array('id', 'title'));
                  //      ->joinLeft(array('a'=>'answers'), 'a.question_id = q.id',array('answers_count'=>'COUNT(a.id)'))
                   //     ->group('q.id');
           //     echo $select->__toString();
                $paginator = new Zend_Paginator(new Zend_Paginator_Adapter_DbSelect($select));
                $paginator->setCurrentPageNumber($this->_getParam('page'));
                $paginator->setItemCountPerPage(2);
                $content = new Application_Model_Content_Live(1);

          $this->view->content =  $content;
          $this->view->title = $content->title;
          $this->view->paginator = $paginator;
    }

    public function roomAction()
    {
         $id = $this->_getParam('id');    
         $room = new Application_Model_Content_Rooms($id);
            $cont = $room->getContent();
            if(is_dir("files/pictures/live/$id")):
                   $dir    =    "files/pictures/live/$id";
            else:
                    mkdir( "files/pictures/live/$id");
                    $dir    =    "files/pictures/live/$id";
            endif;
                            $pic = array();
                            if ($handle = opendir($dir)) :
                                while (false !== ($entry = readdir($handle))) :
                                    if ($entry != "." && $entry != "..") :
                                        if (is_dir($dir."/".$entry) === true):
                                            echo "DIRECTORY: ".$entry."\n";
                                        else:
                                                            $pic[] = $entry;
                                        endif;
                                endif;
                                endwhile;
                                closedir($handle);
                            endif;
            
        $this->view->cont =  $room->getContent();
        $this->view->room = $room;
        $this->view->dir = $dir;
         $this->view->pic = $pic;
        $this->view->title = $room->title;
        
    }


}



